home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
cmds
/
nfsmount
/
RCS
/
nfsAttr.c,v
< prev
next >
Wrap
Text File
|
1991-09-10
|
18KB
|
663 lines
head 1.10;
branch ;
access ;
symbols ;
locks ; strict;
comment @ * @;
1.10
date 91.09.10.19.24.56; author mottsmth; state Exp;
branches ;
next 1.9;
1.9
date 91.06.01.15.54.01; author mottsmth; state Exp;
branches ;
next 1.8;
1.8
date 91.03.23.19.33.22; author mottsmth; state Exp;
branches ;
next 1.7;
1.7
date 90.01.25.17.20.19; author brent; state Exp;
branches ;
next 1.6;
1.6
date 89.10.10.13.14.57; author brent; state Exp;
branches ;
next 1.5;
1.5
date 89.09.20.17.13.22; author douglis; state Exp;
branches ;
next 1.4;
1.4
date 89.02.16.14.40.40; author brent; state Exp;
branches ;
next 1.3;
1.3
date 89.02.02.15.04.19; author brent; state Exp;
branches ;
next 1.2;
1.2
date 88.11.14.15.14.44; author brent; state Exp;
branches ;
next 1.1;
1.1
date 88.11.02.12.44.03; author brent; state Exp;
branches ;
next ;
desc
@Attribute handling procedures
@
1.10
log
@Cleanup memory leaks.
@
text
@/*
* nfsAttr.c --
*
* Attribute handling for NFS access.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/nfsAttr.c,v 1.9 91/06/01 15:54:01 mottsmth Exp Locker: mottsmth $ SPRITE (Berkeley)";
#endif not lint
#include "stdio.h"
#include "nfs.h"
#include "sys/stat.h"
#include "kernel/fslcl.h"
typedef struct SavedCookie {
int offset;
nfscookie cookie;
struct SavedCookie *next;
} SavedCookie;
void NfsToSpriteAttr();
void SpriteToNFsAttr();
/*
*----------------------------------------------------------------------
*
* NfsToSpriteDirectory --
*
* Convert from an XDR list of directory entries to a Sprite directory.
*
* Results:
* This fills in the buffer with a Sprite format directory.
*
* Side effects:
* This saves the last nfscookie for use with the next READIR rpc.
*
*----------------------------------------------------------------------
*/
void
NfsToSpriteDirectory(dirListPtr, offset, countPtr, buffer, fileIDPtr)
dirlist *dirListPtr;
int offset;
int *countPtr;
char *buffer;
Fs_FileID *fileIDPtr;
{
register int count = 0;
register entry *entryPtr;
register Fslcl_DirEntry *spriteEntryPtr;
register int nameLength;
entry *tempEntryPtr;
/* At one time we checked the dirListPtr->eof flag and bailed
out early if it was set. Unfortunately, Sys V sets this
flag even when it returns some directory entries to indicate
that a subsequent request will fail. So now we rely on
the dirListPtr->entries ptr being NULL to indicate no entries.
*/
entryPtr = dirListPtr->entries;
spriteEntryPtr = (Fslcl_DirEntry *)buffer;
while (entryPtr != (entry *)NULL) {
nameLength = strlen(entryPtr->name);
spriteEntryPtr->fileNumber = entryPtr->fileid;
spriteEntryPtr->nameLength = nameLength;
strcpy(spriteEntryPtr->fileName, entryPtr->name);
/* The xdr routines do implicit mallocs which were never
getting freed so I added these two lines. Maybe it
should be done with XDR_FREE ? */
free(entryPtr->name);
entryPtr->name = (filename)NULL;
if (entryPtr->nextentry != (entry *)NULL) {
spriteEntryPtr->recordLength = Fslcl_DirRecLength(nameLength);
count += spriteEntryPtr->recordLength;
spriteEntryPtr = (Fslcl_DirEntry *)((int)spriteEntryPtr +
spriteEntryPtr->recordLength);
} else {
/*
* Make the last entry go up to the end of the directory block.
* We save the last cookie to support sequential reading of the
* directory. To be completely genernal we'd have to save the
* complete list of cookie/offset pairs.
*/
register int extraRoom;
SavedCookie *savedCookie;
extraRoom = FSLCL_DIR_BLOCK_SIZE - (count % FSLCL_DIR_BLOCK_SIZE);
spriteEntryPtr->recordLength = extraRoom;
count += extraRoom;
/*
* Push a saved cookie onto a list hanging from the major field.
*/
savedCookie = (SavedCookie *)malloc(sizeof(SavedCookie));
savedCookie->offset = offset + count;
bcopy((char *)&entryPtr->cookie, (char *)&savedCookie->cookie,
sizeof(nfscookie));
savedCookie->next = (SavedCookie *)fileIDPtr->major;
fileIDPtr->major = (int)savedCookie;
}
/* Also, the implicitly acquired dirlist space wasn't going away,
so we'll zap it here. JMS */
tempEntryPtr = entryPtr;
entryPtr = entryPtr->nextentry;
free(tempEntryPtr);
}
*countPtr = count;
}
/*
*----------------------------------------------------------------------
*
* NfsFindCookie --
*
* Look through the list of savedCookie that are hung off the
* fileID.major field of a directory to find one that corresponds
* to the given offset.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
NfsFindCookie(fileIDPtr, offset, cookiePtr)
Fs_FileID *fileIDPtr;
int offset;
nfscookie *cookiePtr;
{
register SavedCookie *savedCookiePtr;
register SavedCookie *savedCookiePtrTrail = (SavedCookie *)NULL;
int badCookie = -1;
savedCookiePtr = (SavedCookie *)fileIDPtr->major;
while (savedCookiePtr != (SavedCookie *)NULL) {
if (savedCookiePtr->offset == offset) {
bcopy((char *)&savedCookiePtr->cookie, (char *)cookiePtr,
sizeof(nfscookie));
/* Add code to release cookie so we don't lose heap space. JMS */
if (savedCookiePtrTrail == (SavedCookie *)NULL) {
fileIDPtr->major = (int)savedCookiePtr->next;
} else {
savedCookiePtrTrail->next = savedCookiePtr->next;
}
free((char *)savedCookiePtr);
return;
}
savedCookiePtrTrail = savedCookiePtr;
savedCookiePtr = savedCookiePtr->next;
}
printf("NfsFindCookie: no directory cookie for offset %d\n");
bcopy((char *)&badCookie, (char *)cookiePtr, sizeof(nfscookie));
}
/*
*----------------------------------------------------------------------
*
* NfsGetAttrStream --
*
* The default GetAttributes handling procedure called when an
* PDEV_GET_ATTR request is received over a request stream.
*
* Results:
* None.
*
* Side effects
* None.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
ReturnStatus
NfsGetAttrStream(streamPtr, spriteAttrPtr, selectBitsPtr)
Pdev_Stream *streamPtr;
Fs_Attributes *spriteAttrPtr;
int *selectBitsPtr;
{
register Fs_FileID *fileIDPtr = (Fs_FileID *)streamPtr->clientData;
register nfs_fh *handlePtr;
register int status;
NfsState *nfsPtr;
attrstat attrStat;
if (fileIDPtr->minor >= 0 && fileIDPtr->minor < nfsFileTableSize) {
handlePtr = nfsFileTable[fileIDPtr->minor]->handlePtr;
nfsPtr = (NfsState *)fileIDPtr->serverID;
nfsPtr->nfsClnt->cl_auth = nfsFileTable[fileIDPtr->minor]->authPtr;
if (clnt_call(nfsPtr->nfsClnt, NFSPROC_GETATTR, xdr_nfs_fh, handlePtr,
xdr_attrstat, &attrStat, nfsTimeout) != RPC_SUCCESS) {
clnt_perror(nfsPtr->nfsClnt, "NFSPROC_GETATTR");
status = FAILURE;
} else {
status = attrStat.status;
if (status == NFS_OK) {
NfsToSpriteAttr(&attrStat.attrstat_u.attributes, spriteAttrPtr);
} else {
status = NfsStatusMap(status);
}
}
} else {
printf("NfsGetAttrStream: bad fileID <%d,%d,%d,%d>\n", fileIDPtr->type,
fileIDPtr->serverID, fileIDPtr->major, fileIDPtr->minor);
status = FAILURE;
}
*selectBitsPtr = FS_READABLE | FS_WRITABLE;
return(status);
}
/*
*----------------------------------------------------------------------
*
* NfsToSpriteAttr --
*
* Map from NFS to Sprite attributes.
*
* Results:
* Fills in the Sprite attributes from the NFS ones.
*
* Side effects
* None.
*
*----------------------------------------------------------------------
*/
void
NfsToSpriteAttr(nfsAttrPtr, spriteAttrPtr)
register fattr *nfsAttrPtr;
register Fs_Attributes *spriteAttrPtr;
{
spriteAttrPtr->serverID = -1;
spriteAttrPtr->domain = nfsAttrPtr->fsid;
spriteAttrPtr->fileNumber = nfsAttrPtr->fileid;
spriteAttrPtr->type = nfsToSpriteFileType[(int) nfsAttrPtr->type];
spriteAttrPtr->size = nfsAttrPtr->size;
spriteAttrPtr->numLinks = nfsAttrPtr->nlink;
spriteAttrPtr->permissions = nfsAttrPtr->mode & 07777;
spriteAttrPtr->uid = nfsAttrPtr->uid;
spriteAttrPtr->gid = nfsAttrPtr->gid;
spriteAttrPtr->devServerID = -1;
if (nfsAttrPtr->type == NFBLK || nfsAttrPtr->type == NFCHR) {
spriteAttrPtr->devType = unix_major(nfsAttrPtr->rdev);
spriteAttrPtr->devUnit = unix_minor(nfsAttrPtr->rdev);
} else {
spriteAttrPtr->devType = -1;
spriteAttrPtr->devUnit = -1;
}
spriteAttrPtr->createTime.seconds = nfsAttrPtr->mtime.seconds;
spriteAttrPtr->createTime.microseconds = nfsAttrPtr->mtime.useconds;
spriteAttrPtr->accessTime.seconds = nfsAttrPtr->atime.seconds;
spriteAttrPtr->accessTime.microseconds = nfsAttrPtr->atime.useconds;
spriteAttrPtr->descModifyTime.seconds = nfsAttrPtr->ctime.seconds;
spriteAttrPtr->descModifyTime.microseconds = nfsAttrPtr->ctime.useconds;
spriteAttrPtr->dataModifyTime.seconds = nfsAttrPtr->mtime.seconds;
spriteAttrPtr->dataModifyTime.microseconds = nfsAttrPtr->mtime.useconds;
/*
* Sprite "blocks" means 1K. Unix "blocks" mean 512 bytes.
* In both cases, blocksize is the file system block size, which
* has nothing to do with the units of the blocksize field!
*/
spriteAttrPtr->blocks = nfsAttrPtr->blocks / 2;
spriteAttrPtr->blockSize = nfsAttrPtr->blocksize;
spriteAttrPtr->version = nfsAttrPtr->mtime.seconds;
spriteAttrPtr->userType = 0;
}
/*
*----------------------------------------------------------------------
*
* NfsSetAttrStream --
*
* PDEV_SET_ATTR callback to set attributes of an open NFS file.
*
* Results:
* None.
*
* Side effects
* None.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
ReturnStatus
NfsSetAttrStream(streamPtr, flags, uid, gid, spriteAttrPtr, selectBitsPtr)
Pdev_Stream *streamPtr;
int flags; /* What attributes to set */
int uid; /* UserID of process doing the set attr */
int gid; /* GroupID of process doing the set attr */
Fs_Attributes *spriteAttrPtr;
int *selectBitsPtr;
{
register Fs_FileID *fileIDPtr = (Fs_FileID *)streamPtr->clientData;
register nfs_fh *handlePtr;
register int status;
NfsState *nfsPtr;
sattrargs sattrArgs;
attrstat attrStat;
if (fileIDPtr->minor >= 0 && fileIDPtr->minor < nfsFileTableSize) {
handlePtr = nfsFileTable[fileIDPtr->minor]->handlePtr;
nfsPtr = (NfsState *)fileIDPtr->serverID;
nfsPtr->nfsClnt->cl_auth = nfsFileTable[fileIDPtr->minor]->authPtr;
bcopy((char *)handlePtr, (char *)&sattrArgs.file, sizeof(nfs_fh));
SpriteToNfsAttr(flags, spriteAttrPtr, &sattrArgs.attributes);
if (clnt_call(nfsPtr->nfsClnt, NFSPROC_SETATTR, xdr_sattrargs,
&sattrArgs, xdr_attrstat, &attrStat, nfsTimeout)
!= RPC_SUCCESS) {
clnt_perror(nfsPtr->nfsClnt, "NFSPROC_SETATTR");
status = FAILURE;
} else {
status = NfsStatusMap(((int)attrStat.status));
}
} else {
printf("NfsSetAttrStream: bad fileID <%d,%d,%d,%d>\n", fileIDPtr->type,
fileIDPtr->serverID, fileIDPtr->major, fileIDPtr->minor);
status = FAILURE;
}
*selectBitsPtr = FS_READABLE | FS_WRITABLE;
return(status);
}
/*
*----------------------------------------------------------------------
*
* SpriteToNfsAttr --
*
* Map from Sprite to NFS attributes.
*
* Results:
* Fills in the NFS attributes from the Sprite ones.
*
* Side effects
* None.
*
*----------------------------------------------------------------------
*/
void
SpriteToNfsAttr(flags, spriteAttrPtr, nfsAttrPtr)
register int flags; /* Indicate which attrs to set */
register Fs_Attributes *spriteAttrPtr;
register sattr *nfsAttrPtr;
{
if (flags & FS_SET_MODE) {
nfsAttrPtr->mode = spriteAttrPtr->permissions & 07777;
} else {
nfsAttrPtr->mode = -1;
}
if (flags & FS_SET_OWNER) {
nfsAttrPtr->uid = spriteAttrPtr->uid;
nfsAttrPtr->gid = spriteAttrPtr->gid;
} else {
nfsAttrPtr->uid = -1;
nfsAttrPtr->gid = -1;
}
nfsAttrPtr->size = -1; /* Not used for truncate */
if (flags & FS_SET_TIMES) {
nfsAttrPtr->atime.seconds = spriteAttrPtr->accessTime.seconds;
nfsAttrPtr->atime.useconds = spriteAttrPtr->accessTime.microseconds;
nfsAttrPtr->mtime.seconds = spriteAttrPtr->dataModifyTime.seconds;
nfsAttrPtr->mtime.useconds = spriteAttrPtr->dataModifyTime.microseconds;
} else {
nfsAttrPtr->atime.seconds = -1;
nfsAttrPtr->atime.useconds = -1;
nfsAttrPtr->mtime.seconds = -1;
nfsAttrPtr->mtime.useconds = -1;
}
}
/*
*----------------------------------------------------------------------
*
* NfsCacheAttributes --
*
* Cache NFS attributes.
*
* Results:
* None.
*
* Side effects
* Tucks away the attributes with a coarse date stamp.
*
*----------------------------------------------------------------------
*/
void
NfsCacheAttributes(fileIDPtr, nfsAttrPtr)
register Fs_FileID *fileIDPtr;
register fattr *nfsAttrPtr;
{
return;
}
@
1.9
log
@Fixed memory leak due to NfsToSpriteDirectory routine
not freeing space allocated by xdr routines.
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/nfsAttr.c,v 1.8 91/03/23 19:33:22 mottsmth Exp Locker: mottsmth $ SPRITE (Berkeley)";
d111 1
a111 3
so we'll zap it here. BTW, the SavedCookie space
(malloc'd above) isn't being freed either,
but I'm not sure when it's safe to do this. JMS */
d143 1
d151 7
d160 1
@
1.8
log
@Handle eof condition on directory read from Sys V
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/nfsAttr.c,v 1.7 90/01/25 17:20:19 brent Exp Locker: mottsmth $ SPRITE (Berkeley)";
d61 1
d77 5
d110 5
d116 1
@
1.7
log
@Fixed use of 'major' and 'minor' macros
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/nfsAttr.c,v 1.6 89/10/10 13:14:57 brent Exp Locker: brent $ SPRITE (Berkeley)";
d62 7
a68 5
if (dirListPtr->eof) {
*countPtr = 0;
fileIDPtr->major = 0;
return;
}
@
1.6
log
@Updated to new FS typedefs.
Also fixed the block count as returned by the 'df' program.
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /a/newcmds/nfsmount/RCS/nfsAttr.c,v 1.5 89/09/20 17:13:22 douglis Exp Locker: brent $ SPRITE (Berkeley)";
d231 2
a232 2
spriteAttrPtr->devType = major(nfsAttrPtr->rdev);
spriteAttrPtr->devUnit = minor(nfsAttrPtr->rdev);
@
1.5
log
@Removed lint
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /a/newcmds/nfsmount/RCS/nfsAttr.c,v 1.4 89/02/16 14:40:40 brent Exp Locker: douglis $ SPRITE (Berkeley)";
d23 1
a23 1
#include "kernel/fsDisk.h"
d59 1
a59 1
register FsDirEntry *spriteEntryPtr;
d68 1
a68 1
spriteEntryPtr = (FsDirEntry *)buffer;
d75 1
a75 1
spriteEntryPtr->recordLength = FsDirRecLength(nameLength);
d77 1
a77 1
spriteEntryPtr = (FsDirEntry *)((int)spriteEntryPtr +
d89 1
a89 1
extraRoom = FS_DIR_BLOCK_SIZE - (count % FS_DIR_BLOCK_SIZE);
d245 6
a250 1
spriteAttrPtr->blocks = nfsAttrPtr->blocks;
@
1.4
log
@Fixed FS_SET_MODE to ignore the 'type' field in the Sprite
attributes structure instead of trying to map it to IF_REG
or whatever. The 'type' field is not defined during FS_SET_MODE.
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /a/newcmds/nfsmount/RCS/nfsAttr.c,v 1.3 89/02/02 15:04:19 brent Exp $ SPRITE (Berkeley)";
d223 1
a223 1
spriteAttrPtr->type = nfsToSpriteFileType[nfsAttrPtr->type];
d296 1
a296 1
status = NfsStatusMap(attrStat.status);
@
1.3
log
@Updated to new pfs package.
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /a/newcmds/nfssrv/RCS/nfsAttr.c,v 1.2 88/11/14 15:14:44 brent Exp $ SPRITE (Berkeley)";
a329 5
if (spriteAttrPtr->type >= 0 && spriteAttrPtr->type <= FS_XTRA_FILE) {
nfsAttrPtr->mode |= spriteToNfsModeType[spriteAttrPtr->type];
} else {
printf("SpriteToNfsAttr bad file type %d\n", spriteAttrPtr->type);
}
@
1.2
log
@Added user authentication
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: /sprite/users/brent/nfstest/RCS/nfsAttr.c,v 1.1 88/11/02 12:44:03 brent Exp $ SPRITE (Berkeley)";
d104 1
d164 2
a165 2
NfsGetAttrStream(private, spriteAttrPtr, selectBitsPtr)
ClientData private;
d169 1
a169 1
register Fs_FileID *fileIDPtr = (Fs_FileID *)private;
d268 2
a269 2
NfsSetAttrStream(private, flags, uid, gid, spriteAttrPtr, selectBitsPtr)
ClientData private;
d276 1
a276 1
register Fs_FileID *fileIDPtr = (Fs_FileID *)private;
@
1.1
log
@Initial revision
@
text
@d16 1
a16 1
static char rcsid[] = "$Header: fsPfs.c,v 6.0 88/10/11 15:52:49 brent Exp $ SPRITE (Berkeley)";
d169 1
a169 1
register nfs_fh *handlePtr = nfsHandleTable[fileIDPtr->minor];
d174 2
a175 2
if (fileIDPtr->minor >= 0 && fileIDPtr->minor < nfsHandleTableSize) {
handlePtr = nfsHandleTable[fileIDPtr->minor];
d177 1
d276 1
a276 1
register nfs_fh *handlePtr = nfsHandleTable[fileIDPtr->minor];
d282 2
a283 2
if (fileIDPtr->minor >= 0 && fileIDPtr->minor < nfsHandleTableSize) {
handlePtr = nfsHandleTable[fileIDPtr->minor];
d285 1
@